home *** CD-ROM | disk | FTP | other *** search
- ///campfire particle shader
- //input should be 4 points that are the same position
- //color0 (diffuse) used normally
- //color1 (spec): green,red are tex coord, blue = size modifier
- //Luke Lenhart
- //(C)2004-2005 Digipen Institute of Technology
-
- //world,view,projection transform
- float4x4 matWorldViewProj;
-
- //camera position in world space
- float4 cameraPos;
-
- //particle size modifier
- float size;
-
- //shader input
- struct VS_INPUT
- {
- float4 Pos : POSITION;
- float4 Color : COLOR0;
- float4 Spec : COLOR1;
- };
-
- //shader output
- struct VS_OUTPUT
- {
- float4 Pos : POSITION;
- float4 Color : COLOR;
- float2 Tex0 : TEXCOORD0;
- };
-
- //shader code
- VS_OUTPUT VShader(VS_INPUT In)
- {
- VS_OUTPUT Out;
-
- //transform pos and copy tex coord and color over
- Out.Pos=mul(matWorldViewProj,In.Pos);
- Out.Tex0=In.Spec.xy;
- Out.Color=In.Color;
-
- //expand outwards from center point, based on distance and tex coord
- float distmod=0.08f + 1.0f / pow(distance(cameraPos,In.Pos),0.5f);
- float2 posOffset=In.Spec.xy - float2(0.5f,0.5f);
- float sizeMod=(0.5f + In.Spec.z*2.0f);
-
- Out.Pos.xy+=posOffset*distmod*size*sizeMod;
-
- //spit out the results
- return Out;
- }
-